#!/usr/bin/python3

import os
import struct

PORT_RES = '/dev/port'
COLD_RESET = 0xE     # Cold Reset
WARM_RESET = 0x6     # Warm Reset
RESET_REG = 0xCF9

def io_reg_write(resource, offset, val):
    fd = os.open(resource, os.O_RDWR)
    if(fd < 0):
        print('file open failed %s" % resource')
        return
    if(os.lseek(fd, offset, os.SEEK_SET) != offset):
        print('lseek failed on %s' % resource)
        return
    ret = os.write(fd, struct.pack('B', val))
    if(ret != 1):
        print('write failed %d' % ret)
        return
    os.close(fd)


if __name__ == "__main__":
    io_reg_write(PORT_RES, RESET_REG, COLD_RESET) 
